<?php
// load the theme options
$options = get_option( 'complete_theme_settings' );
// get portfolio column count
if($options['portfolio_column'] != '') {
$portfolio_count = $options['portfolio_column'];
} else { $portfolio_count = 'four'; }
?>
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header(' '); ?>
<div id="main" class="clearfix">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="portfolio-top">
    	<h1 id="page-title"><?php the_title(' '); ?></h1>			
    	<?php the_content(' '); ?>
    	<?php endwhile; ?>
    </div>
    <!-- END portfolio-top -->
    <?php endif; ?>	
    <div id="portfolio-wrap">
        <ul id="portfolio-filter" class="clearfix">
			<?php if ($options['disable_portfolio_filter'] != true) { ?>
            <li><a href="#all">all</a></li>
            <?php 
            $cats = get_terms('portfolio_cats');
            foreach ($cats as $cat ) : ?>
            <li><a href="#<?php echo $cat->slug; ?>" rel="<?php echo $cat->slug; ?>"><?php echo $cat->name; ?></a></li>
            <?php endforeach; ?>
            <?php } ?>
        </ul>
    	<!-- END portfolio-navigation -->	
        <div id="portfolio-<?php echo $portfolio_count ?>-column" class="clearfix">
            <ul id="portfolio-list">
                <?php
                    $portfolio_posts = new WP_Query(array(
                        'post_type' =>'portfolio',
                        'posts_per_page' => -1,
                        'orderby' => 'ASC'
                    ));
                ?>
                <?php
                    while($portfolio_posts->have_posts()) : $portfolio_posts->the_post();
                ?>
                <?php
                    $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); 
                    $terms = get_the_terms ($post->id, 'portfolio_cats');
                ?>
                <li class="portfolio-box <?php if($terms) {  foreach ($terms as $term) { echo $term->slug . ' '; } } ?>">
                    <div class="portfolio-box-image">
                        <a href="<?php echo $thumbnail[0]; ?>" title="<?php the_title('') ?>" rel="prettyPhoto[gallery]" class="opacity"><?php the_post_thumbnail('portfolio-'. $portfolio_count .'-column'); ?><span class="portfolio-magnify"></span></a>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="portfolio-view-work">→</a>
                    </div>
                    <!-- END portfolio-box-image -->
                   <?php
                    // check if portfolio titles are disabled, otherwise show them
                    if ($options['disable_portfolio_title'] != true) { ?>
                    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                    <?php } ?>
                    <?php
                    // check if portfolio details are disabled, otherwise show them
                    if ($options['disable_portfolio_details'] != true) { ?>
                    <?php echo get_post_meta($post->ID, 'portfolio_description', true); ?>   
                    <?php } ?>
                </li>
                <!-- END portfolio-box -->
                <?php endwhile; ?>
            </ul>
            <!-- END portfolio-list -->
        </div>
        <!-- END portfolio-<?php echo $portfolio_count ?>-column -->
</div>
<!-- END portfolio-wrap -->
<?php get_footer(' '); ?>